package org.shiwen.week11;

public class ThrowException {
    public static void main(String[] args) {
        Student s = new Student();
        System.out.println("234");
//        s.setAge(17);
//        System.out.println("123");

        try{
            s.setAge(17);
        }catch (RuntimeException e){
            System.out.println("年龄不能小于18岁");
        }
        System.out.println("123");
    }
}

class Student{
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if(age<18){
//            System.out.println("年龄不能小于18岁");
            throw new RuntimeException();
        }else{
            this.age= age;
        }
    }
}
